var app = new Vue({
	  el: '#AddPhoto',
	  data: {
	  	basicsInformationId: 0,
	  	controller: {
            isPhotoCon: false,
            alertText: false
        },
	  	navIndexAct:{
            ind:1,
            nextText:'下一步',
            navTitle:[
                {title:'1 头像添加',},
                {title:'2 证书照片',},
                {title:'3 工作照片',},
                {title:'全部添加完成！',}
               
            ]
        },
        selectVale: 0,
        headPortrait:'images/icon.jpg',
        CertificatList:[],
        HistoryList:[],
	  },
	  methods:{
	  	pageNext: function() {
	  		


	  		switch (this.navIndexAct.ind){
					case 1:
						this.navIndexAct.ind ++ ;
						this.navIndexAct.nextText = '下一步';
					  break;
					case 2:
						this.navIndexAct.ind ++ ;
						this.navIndexAct.nextText = '完成';
					  break;
					case 3:


						var datainfo = {
								Personal: {
									id: app.basicsInformationId,
									avatar: app.headPortrait == 'images/icon.jpg' ? ' ' : app.headPortrait,
								},
								CertificatList: app.CertificatList,
	  							HistoryList: app.HistoryList,

						}

						$.ajax({
							url: severUrl + 'addHouseworker',
							type: 'POST',
							dataType: 'JSON',
							data: datainfo,
						})
						.done(function(data) {
							console.log("success");

							if (data.success) {
								app.navIndexAct.ind ++ ;
							}

						})

						console.log(datainfo)
						console.log(JSON.stringify(datainfo))
												

					  break;
					
				}

	  	},
	  	DeletePhotoSon:function(index, item) {
	  		if (item.id != 0) {

	  			$.ajax({
	  				url: severUrl +'delPhoto?id=' + item.id,
	  				type: 'GET',
                    dataType: 'JSON',
	  			})
	  			.done(function(data) {
	  				console.log("success");
	  				if (data.success) {

	  					app.HistoryList[app.selectVale].PhotoList.splice(index, 1);
                        app.AlertConFun('删除成功！')
                    }

	  			})
	  				  			

	  		}else{
	  			this.HistoryList[app.selectVale].PhotoList.splice(index, 1);
	  			this.AlertConFun('删除成功！')


	  		}

	  	},
	  	DeleteHistoryList:function(index, item) {
	  		$.ajax({
	  				url: severUrl +'delPhotoByWorkid?id=' + item.id,
	  				type: 'GET',
                    dataType: 'JSON',
	  			})
	  			.done(function(data) {
	  				console.log("success");
	  				if (data.success) {
	  					item.PhotoList.splice(0, item.PhotoList.length);
                        app.AlertConFun('删除成功！')
                    }

	  			})

	  	},
	  	AddPhotoList:function() {

	  		var url = $('#fileList').find('img.photo').attr('src');

	  		if (url) {
				switch (this.navIndexAct.ind){
					case 1:
					  this.headPortrait = url;
					  break;
					case 2:
					  this.CertificatList.unshift({id:0, pic: url})
					  break;
					case 3:
						this.HistoryList[app.selectVale].PhotoList.unshift({id:0, pic: url})
					  
					  break;
					case 4:
					  // x="Today it's Thursday";
					  break;
				}
	  			$('#fileList').html('');
				this.controller.isPhotoCon = false;
	  		}else{
	  			this.AlertConFun('请添加照片')

	  		}



	  	},
	  	DeleteCertificatList: function(index, item){
	  		if (item.id != 0) {
	  			$.ajax({
	  				url: severUrl +'delCertificat?id=' + item.id,
	  				type: 'GET',
                    dataType: 'JSON',
	  			})
	  			.done(function(data) {
	  				console.log("success");
	  				if (data.success) {
                        app.CertificatList.splice(index, 1);
                        app.AlertConFun('删除成功！')
                    }

	  			})
	  				  			

	  		}else{
	  			this.CertificatList.splice(index, 1);
                this.AlertConFun('删除成功！')
	  		}
	  	},
	  	AlertConFun: function(string) {
            this.controller.alertText = string;

            setTimeout(function(argument) {
                this.app._data.controller.alertText = false;
            },1500)

        },




	  },


	  created:function () {
	  	var phone = loginObj.getLogoinInfo() || 0;
	  	// var phone = 15;
	  	$.ajax({
	  		url: severUrl+'getHouseworker?phone=' + phone,
            type: 'GET',
            dataType: 'JSON'
	  	})
	  	.done(function(data) {
	  		console.log("success");
	  		console.log(data);

	  		if (true) {
	  			app.basicsInformationId = data.Personal.id;
	  			app.headPortrait = data.Personal.avatar || 'images/icon.jpg';
	  			app.CertificatList =  data.CertificatList;
	  			app.HistoryList =  data.HistoryList;
	  		}


	  	})
	  }
})

